gadget: Warn about missing size allocation
authorMatthias Clasen <mclasen@redhat.com>
Thu, 25 Feb 2016 03:18:13 +0000 (22:18 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 25 Feb 2016 03:22:11 +0000 (22:22 -0500)
When size_allocate is overridden in widgets, but draw is not,
we can end up drawing a gadget that has not been given a size.

Warn about this, and limp along by drawing the gadget over the
full allocation of its owner widget.

https://bugzilla.gnome.org/show_bug.cgi?id=762614

gtk/gtkcssgadget.c

index 5bb7cac151bbda4ac6f3ab82f666f447f9133b04..b907839dc2f73a543f43ea2b769cc2a2a021a6be 100644 (file)
@@ -284,7 +284,11 @@ gtk_css_gadget_class_init (GtkCssGadgetClass *klass)
 static void
 gtk_css_gadget_init (GtkCssGadget *gadget)
 {
+  GtkCssGadgetPrivate *priv = gtk_css_gadget_get_instance_private (gadget);
 
+  priv->allocated_size.width = -1;
+  priv->allocated_size.height = -1;
+  priv->allocated_baseline = -1;
 }
 
 /**
@@ -729,6 +733,16 @@ gtk_css_gadget_draw (GtkCssGadget *gadget,
   width = priv->allocated_size.width;
   height = priv->allocated_size.height;
 
+  if (width < 0 || height < 0)
+    {
+      g_warning ("Drawing a gadget with negative dimensions. "
+                 "Did you forget to allocate a size?");
+      x = 0;
+      y = 0;
+      width = gtk_widget_get_allocated_width (priv->owner);
+      height = gtk_widget_get_allocated_height (priv->owner);
+    }
+
   style = gtk_css_gadget_get_style (gadget);
   get_box_margin (style, &margin);
   get_box_border (style, &border);